﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TCP_Spy
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void button_连接_Click(object sender, EventArgs e)
        {
            string IP = textBox_IP.Text;
            string Port = textBox_端口.Text;

            if (button_连接.Text == "连接")
            {
                if (IP != "" && Port != "")
                {
                    if (Socket_Class.TCP_Connect(IP, Port)) // 与服务器建立连接 成功返回 true  否则 false
                    {

                        label_状态.Text = "已连接";
                        button_连接.Text = "断开";
                    }
                    else
                    {
                        label_状态.Text = "未连接";
                        MessageBox.Show("连接错误");
                    }
                }
            }
            else if (button_连接.Text == "断开")
            {
                Socket_Class.socket_close();
            }
        }

        private void textBox_IP_DoubleClick(object sender, EventArgs e)
        {
            textBox_IP.Text = Socket_Class.Initial_Value_IP;
            textBox_端口.Text = Socket_Class.Initial_Value_Port;
        }

        private void textBox_端口_DoubleClick(object sender, EventArgs e)
        {
            textBox_IP.Text = Socket_Class.Initial_Value_IP;
            textBox_端口.Text = Socket_Class.Initial_Value_Port;
        }

        private void button_退出_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
